package com.cn.qgx428.lazydiary

import android.app.Application
import android.content.Intent
import com.cn.qgx428.lazydiary.prump.service.ClockService
import com.cn.qgx428.lazydiary.ui.activity.BaseActivity

/**
 * Created by QinX on 2017/12/12.
 */
class APP : Application(){
    override fun onCreate() {
        super.onCreate()
        mApp = this

        //
        val clockServiceIntent = Intent(this, ClockService::class.java)
        startService(clockServiceIntent)
    }



    companion object {
        val TAG = "APP"
        lateinit var mApp : APP
            private set
        // 用于管理活动栈
        var activities : MutableList<BaseActivity> = mutableListOf()

        public fun addActivity(activity : BaseActivity) = activities.add(activity)
        public fun removeAcitivity(activity: BaseActivity) = activities.remove(activity)
        public fun claerActivity() = activities.let {
            while (it.iterator().hasNext()){
               it.iterator().next()?.finish()
            }
        }

        public fun getAppContext() = mApp
    }
}